package com.siwei.eqi.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.siwei.eqi.pojo.entity.IndexCalculationSubTaskEntity;
import com.siwei.eqi.service.IndexCalculationSubTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 指数计算子任务
 */
@RestController
@RequestMapping("/IndexCalculationSubTask")
public class IndexCalculationSubTaskController {
    @Autowired
    private IndexCalculationSubTaskService indexCalculationSubTaskService;

    /**
     * 指数计算子任务查询列表
     *
     * @param entity
     * @return
     */
    @GetMapping
    public R getList(IndexCalculationSubTaskEntity entity) {
        try {
            return indexCalculationSubTaskService.getList(entity);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @PostMapping("/addIndexCalculationSubTask")
    public R addIndexCalculationSubTask(String calculationArea) {
        try {
            IndexCalculationSubTaskEntity indexCalculationSubTaskEntity = new IndexCalculationSubTaskEntity();
            indexCalculationSubTaskEntity.setCalculationArea(calculationArea);
            indexCalculationSubTaskService.addIndexCalculationSubTask(indexCalculationSubTaskEntity);
        } catch (Exception e) {
            return R.failed(e.getMessage());
        }
        return R.ok(null);
    }
}
